

<template>
  <div class="app-container">
    <v-GetToolBar :MenuCode="MenuCode"></v-GetToolBar>
    <div id="divSearch" ref="divSearch">
      <el-form
        :inline="true"
        :model="Search"
        class="demo-form-inline"
        size="mini"
      >
        <el-form-item label="日期" prop="Search">
          <el-date-picker
            v-model="Search.CreatedOn"
            type="daterange"
            start-placeholder="开始日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            end-placeholder="结束日期"
            :default-time="['00:00:00', '00:00:00']"
          />
        </el-form-item>
        <el-form-item label="单位名称：">
          <el-select
            :disabled="false"
            v-model="Search.orged"
            placeholder="请选择"
          >
            <el-option
              :label="item.Organizename"
              :value="item.Organizeid"
              v-for="item in selectDepList"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="月份：">
          <el-date-picker
            type="month"
            v-model="Search.RecruitmentAllowanceDate_Datatime"
            placeholder=" 月份"
          />
        </el-form-item>
        <el-form-item label="编号" prop="Search">
          <el-input
            v-model.trim="Search.RecruitmentSubsidyNo"
            placeholder="编号"
          />
        </el-form-item>

        <el-form-item label="状态" prop="Search">
          <el-select v-model="Search.Status" placeholder="请选择">
            <el-option
              v-for="item in cities"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
              <span style="float: left">{{ item.label }}</span>
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </div>

    <el-table
      :data="DataList"
      :height="tableHeight"
      style="width: 100%; margin-top: 0px"
      border
      @sort-change="sortChange"
    >
      <el-table-column align="center" label="编号">
        <template slot-scope="scope">
          {{ scope.row.RecruitmentSubsidyNo }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="单位名称">
        <template slot-scope="scope">
          {{ scope.row.Organizename }}
        </template>
      </el-table-column>

      <el-table-column
        align="center"
        label="月份"
        width="100"
        prop="RecruitmentAllowanceDate"
        :formatter="formatDateMoth"
      >
      </el-table-column>
      <el-table-column align="header-center" label="审核状态" width="100">
        <template slot-scope="scope">
          {{ scope.row.BillStateName }}
        </template>
      </el-table-column>

      <el-table-column align="header-center" label="当前审核人" width="110">
        <template slot-scope="scope">
          {{ scope.row.NextAduitManName }}
        </template>
      </el-table-column>

      <el-table-column
        align="center"
        label="申请时间"
        prop="RecruitmentAllowanceDate"
        :formatter="formatDate"
      >
      </el-table-column>

      <el-table-column align="header-center" label="创建人" width="110">
        <template slot-scope="scope">
          {{ scope.row.CreatedByName }}
        </template>
      </el-table-column>
      <el-table-column align="header-center" label="创建时间">
        <template slot-scope="scope">
          {{ scope.row.CreatedOn }}
        </template>
      </el-table-column>
      <!-- <el-table-column align="header-center" label="修改人" width="110">
        <template slot-scope="scope">
          {{ scope.row.ModifiedByName }}
        </template>
      </el-table-column>
      <el-table-column align="header-center" label="修改时间">
        <template slot-scope="scope">
          {{ scope.row.ModifyedOn }}
        </template>
      </el-table-column> -->
      <el-table-column align="center" fixed="right" width="150" label="操作">
        <template slot-scope="scope">
          <el-button
            type="primary"
            size="small"
            v-if="IsfunEdit == true"
            @click="handleEdit(scope)"
            >修改</el-button
          >
          <el-button
            type="danger"
            size="small"
            v-if="Isfunfail == true"
            @click="handleDelete(scope)"
            >作废</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="sizes, prev, pager, next,total"
      :page-size="Search.pageSize"
      :total="Search.total"
      @current-change="pageChange"
    />

    <el-dialog
      v-if="dialogVisible"
      :visible.sync="dialogVisible"
      width="1000px"
      top="20px"
    >
      <el-form :model="name" label-width="80px" label-position="left">
        <v-RecruitmentSubsidyForm
          :inputName="inputName"
        ></v-RecruitmentSubsidyForm>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import path from "path";
import { deepClone } from "@/utils";
import {
  getDataList,
  updateForm,
  DeleteForm,
  ALLsubmit,
} from "@/api/RecruitmentSubsidyForm";
import vRecruitmentSubsidyForm from "./RecruitmentSubsidyForm";
import { funDownload } from "@/api/Common";
import vGetToolBar from "../Common/GetToolBar";
// 默认的编辑字段
const defaultObject = {};

export default {
  name: "RecruitmentAllowanceAppyBill",
  components: {
    vRecruitmentSubsidyForm,
    vGetToolBar,
  },

  data() {
    return {
      cities: [
        {
          value: "",
          label: "请选择",
        },
        {
          value: "0",
          label: "草稿",
        },
        {
          value: "1",
          label: "审核中",
        },
        {
          value: "2",
          label: "结案",
        },
        {
          value: "3",
          label: "作废",
        },
      ],
      value: "",
      tableHeight: null,
      tableHeight1: 400,
      EditObj: [],
      inputName: "",
      MenuCode: "A791002",
      IsfunEdit: false,
      Isfunfail: false,
      DataListCost: [],
      DataList: [], //队列的列表 在el-table中用
      selectDepList: [],
      dialogVisible: false,
      Search: {
        // 查询条件
        total: 0, // 总记录数
        pageSize: 10, // 一页显示的记录数
        page: 1, // /当前页码
        RNO: "005", // 表编号  根据Controller中对应的表编号
        jsWhere: "", // 自定义条件
      },
    };
  },
  computed: {
    routesData() {
      return this.routes;
    },
  },
  created() {
    // Mock: get all routes and roles list from server

    this.getDataList();
  },
  mounted() {
    setTimeout(() => {
      this.tableHeight = window.innerHeight - 240 + "px";
    });
  },
  methods: {
    pageChange(page) {
      // 翻页
      this.Search.page = page;

      this.getDataList();
    },
    async getDataList() {
      // 获取列表数据，通用
      const res = await getDataList({ data: JSON.stringify(this.Search) });
      this.DataList = res.data.Table; //将data 中的数据放到DataList中

      this.selectDepList = res.data1.Table;
      this.Search.total = res.data.Table1[0].RecordCount;
    },
    sortChange: function (column) {
      // column, prop, order,排序，通用

      this.Search.sort = column.prop + " " + column.order;

      this.getDataList();
    },
    formatDate(row, column) {
      // 获取单元格数据

      let data = row[column.property];
      if (data == null) {
        return "";
      }
      let dt = new Date(data);
      return dt.getFullYear() + "-" + (dt.getMonth() + 1) + "-" + dt.getDate();
    },
    formatDateMoth(row, column) {
      // 获取单元格数据

      let data = row[column.property];
      if (data == null) {
        return "";
      }
      let dt = new Date(data);
      return dt.getFullYear() + "-" + (dt.getMonth() + 1);
    },
    handeAdd() {
      // 新建

      let routeUrl = this.$router.push({
        path: "/Recruitment/RecruitmentSubsidyForm",
        query: { billID: "", IsPostBack: false },
      });
      window.open(routeUrl.href, "_top");
    },
    handleEdit(scope) {
      // 修改

      let routeUrl = this.$router.push({
        path: "/Recruitment/RecruitmentSubsidyForm",
        query: { billID: scope.row.RecruitmentSubsidyNo, IsPostBack: false },
      });
      window.open(routeUrl.href, "_top");

      this.inputName = scope.row.RecruitmentSubsidyNo;
    },
    async handleALLsubmit() {
      this.$confirm("确定批量提交单据吗?", "警告", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          if (this.Search.RecruitmentAllowanceDate_Datatime == null) {
            this.$message({
              type: "error",
              message: "请选择月份!",
            });

            return;
          }

          const result = await ALLsubmit({
            RecruitmentAllowanceDate: JSON.stringify(
              this.Search.RecruitmentAllowanceDate_Datatime
            ),
            TypeID: 2,
          });

          if (result.code === 20000) {
            this.getDataList();

            this.$message({
              type: "success",
              message: result.meg,
            });
          } else {
            this.$message({
              type: "error",
              message: result.meg,
            });
          }
        })
        .catch((err) => {
          console.error(err);
        });
    },
    handlexportData() {
      funDownload("1536", JSON.stringify(this.Search));
    },
    async handleDelete({ $index, row }) {
      this.$prompt("请填写作废原因：", "提示", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
      }).then(async ({ value }) => {
        if (value == "" || value == null) {
          this.$notify({
            title: "作废失败",
            dangerouslyUseHTMLString: true,
            message: "作废原因不能为空。",
            type: "error",
          });
        } else {
          await DeleteForm({
            billID: row.RecruitmentSubsidyNo,
            Remark: JSON.stringify(value),
          });
          this.DataList.splice($index, 1);
          if (result.code === 20000) {
            this.dialogVisible = false;
            this.$notify({
              title: "Success",
              dangerouslyUseHTMLString: true,
              message: result.message,
              type: "success",
            });
          } else {
            this.$notify({
              title: "error",
              dangerouslyUseHTMLString: true,
              message: result.message,
              type: "error",
            });
          }
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.app-container {
  .EditObjs-table {
    margin-top: 30px;
  }

  .permission-tree {
    margin-bottom: 5px;
  }
}
</style>
